<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>返回顶部</title>
    <style>
        body{
            height: 1200px;
        }
        .goBack{
            position: absolute;
            left: 80%;
            top: 90%;
            display: none;
        }
    </style>
</head>
<body>
    <div class="goBack">顶部</div>
    <script>
        var goBack = document.querySelector('.goBack')
        window.addEventListener('scroll',function(){
            if(window.pageYOffset >= 200){
                goBack.style.display = 'block'
            }
            else{
                goBack.style.display = 'none'
            }
        })
        goBack.addEventListener('click',function(){
            window.scroll(0,0)
        })
    </script>
</body>
</html>